Working with Grouping

Changing the existing group's condition field

For this scenario, assume that a report has been created which is currently grouped on the City field (For example, }Customer.City}). To change the condition field for the existing field at runtime, you can use the following code.

Note:    This code assumes that you know which field you want to change and that there is only one group in the report.

You can place this code in the General Declarations section.

Dim CRXReport As New CrystalReport1 'The existing report (ActiveX Designer) 
Dim CRXDBField As CRAXDRT.DatabaseFieldDefinition 

You can put this code in the FORM_LOAD event procedure.

Private Sub Form_Load() 

Currently the group is based on the CITY field, but you want to change it to the REGION field. This code accesses the first table to get the 12th field which is the REGION field.

set CRXDBField = CRXReport.Database.Tables.Item(1).Fields.Item(12) 

Now you can set the new condition field for the existing group. Since you know that there is only one group in the report, you can reference it by its name "GH".

CRXReport.Areas.Item("GH").GroupConditionField = CRXDBField 

Finally, display the report.

CRViewer1.ReportSource = CRXReport 
CRViewer1.ViewReport 

End Sub



Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com